package cn.com.guage.dtm.stat.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.stat.domain.StatDataCheck;
import cn.com.guage.dtm.stat.service.IStatDataCheckService;
import cn.com.guage.dtm.verify.domain.VerifyFieldRuleManage;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.common.core.page.TableDataInfo;

/**
 * 数据检核分析Controller
 * 
 * @author yangdechao
 * @date 2021-06-21
 */
@Controller
@RequestMapping("/stat/check")
public class StatDataCheckController extends BaseController
{
    private String prefix = "stat/check";

    @Autowired
    private IStatDataCheckService statDataCheckService;

    @RequiresPermissions("stat:check:view")
    @GetMapping()
    public String check()
    {
        return prefix + "/check";
    }

    /**
     * 查询数据检核分析列表
     */
    @RequiresPermissions("stat:check:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatDataCheck statDataCheck)
    {
        startPage();
        List<StatDataCheck> list = statDataCheckService.selectStatDataCheckList(statDataCheck);
        return getDataTable(list);
    }

    /**
     * 导出数据检核分析列表
     */
    @RequiresPermissions("stat:check:export")
    @Log(title = "数据检核分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatDataCheck statDataCheck)
    {
        List<StatDataCheck> list = statDataCheckService.selectStatDataCheckList(statDataCheck);
        ExcelUtil<StatDataCheck> util = new ExcelUtil<StatDataCheck>(StatDataCheck.class);
        return util.exportExcel(list, "数据检核分析数据");
    }

    /**
     * 新增数据检核分析
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据检核分析
     */
    @RequiresPermissions("stat:check:add")
    @Log(title = "数据检核分析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatDataCheck statDataCheck)
    {
        return toAjax(statDataCheckService.insertStatDataCheck(statDataCheck));
    }

    /**
     * 修改数据检核分析
     */
    @GetMapping("/edit/{checkResultId}")
    public String edit(@PathVariable("checkResultId") Long checkResultId, ModelMap mmap)
    {
        StatDataCheck statDataCheck = statDataCheckService.selectStatDataCheckById(checkResultId);
        mmap.put("statDataCheck", statDataCheck);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据检核分析
     */
    @RequiresPermissions("stat:check:edit")
    @Log(title = "数据检核分析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatDataCheck statDataCheck)
    {
        return toAjax(statDataCheckService.updateStatDataCheck(statDataCheck));
    }

    /**
     * 删除数据检核分析
     */
    @RequiresPermissions("stat:check:remove")
    @Log(title = "数据检核分析", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statDataCheckService.deleteStatDataCheckByIds(ids));
    }
    
    @RequiresPermissions("stat:check:showCheckDetailPage")
	@GetMapping("/showCheckDetailPage/{checkResultId}")
	public String showCheckDetailPage(@PathVariable("checkResultId") Long checkResultId, ModelMap mmap) {
		mmap.put("checkResultId", checkResultId);
		return prefix + "/check-table-list";
	}
    
}
